import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:raze/potions/raze_constant.dart';
import 'package:raze/potions/spatial_alchemy.dart';

class UploadEmissaryDialog {
  static void revealUploadEmissary({
    required Function() onCommunityTap,
    required Function() onDiaryTap,
  }) {
    Get.dialog(
      _UploadEmissaryWidget(
        onCommunityTap: onCommunityTap,
        onDiaryTap: onDiaryTap,
      ),
      barrierColor: Colors.transparent,
      barrierDismissible: true,
    );
  }
}

/// 上传弹窗内部组件
class _UploadEmissaryWidget extends StatelessWidget {
  final Function() onCommunityTap;
  final Function() onDiaryTap;

  const _UploadEmissaryWidget({
    required this.onCommunityTap,
    required this.onDiaryTap,
  });

  @override
  Widget build(BuildContext context) {
    return Dialog(
      backgroundColor: Colors.transparent,
      elevation: 0,
      alignment: Alignment.bottomCenter,
      insetPadding: EdgeInsets.only(bottom: 70.h),
      child: LayoutBuilder(
        builder: (context, constraints) {
          final screenWidth = constraints.maxWidth;
          final popWidth = screenWidth - 100.w;
          final popHeight = popWidth * (80 / 267);

          return SizedBox(
            width: popWidth,
            height: popHeight,
            child: Stack(
              clipBehavior: Clip.none,
              children: [
                // 背景图片
                Positioned.fill(
                  child: Image.asset(
                    'assets/images/upload-pop-background.png',
                    width: popWidth,
                    height: popHeight,
                    fit: BoxFit.fill,
                  ),
                ),
                Positioned(
                  left: -8.w,
                  top: -60.h,
                  child: Image.asset(
                    'assets/images/upload-decoration.png',
                    width: 80.w,
                    height: 80.w,
                    fit: BoxFit.contain,
                  ),
                ),
                // 两个按钮
                Positioned.fill(
                  child: Padding(
                    padding: EdgeInsets.only(
                      left: 16.w,
                      right: 16.w,
                      top: 12.h,
                      bottom: 26.h,
                    ),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        // Community 按钮
                        Expanded(
                          child: _buildOptionButton(
                            text: 'Community',
                            onTap: () {
                              Get.back();
                              onCommunityTap();
                            },
                          ),
                        ),
                        12.w.boxWidth,
                        // Diary 按钮
                        Expanded(
                          child: _buildOptionButton(
                            text: 'Diary',
                            onTap: () {
                              Get.back();
                              onDiaryTap();
                            },
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          );
        },
      ),
    );
  }

  /// 构建选项按钮
  Widget _buildOptionButton({required String text, required Function() onTap}) {
    return Container(
      height: 44.h,
      decoration: BoxDecoration(
        color: RazeConstants.blue,
        borderRadius: BorderRadius.circular(12.r),
        border: Border.all(color: RazeConstants.black, width: 2.w),
      ),
      child: Center(
        child: Text(text)
            .applyTypeSize(18.sp)
            .applyTypeColor(RazeConstants.white)
            .applyBagelFatOne(
              weight: FontWeight.w400,
              shadows: [
                Shadow(
                  offset: const Offset(1, 1),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: const Offset(-1, -1),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: const Offset(1, -1),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
                Shadow(
                  offset: const Offset(-1, 1),
                  blurRadius: 0,
                  color: RazeConstants.black,
                ),
              ],
            ),
      ),
    ).withTouchResonance(onTap: onTap);
  }
}
